var text_num = 64000;
var text = document.querySelector('.text');
console.log(text);
// 文字计数
var text_timer = setInterval(function () {
    if (text_num == 65000) {
        clearInterval(text_timer);
    }
    text.innerHTML = text_num;
    text_num++;
}, 0.01)
window.addEventListener('load', function () {
    var arrow_1 = document.querySelector('.lt');
    var arrow_r = document.querySelector('.ri');
    var yuan = document.querySelector('.yuan');
    var yuan_ul = yuan.querySelector("ul");
    var banner_focus = document.querySelector('.focus');
    var banner_ul = banner_focus.querySelector('ul');
    var hearder = document.querySelector('.hearder-all');

    var num = 0;
    var circle = 0;



    banner_focus.addEventListener('mouseenter', function () {
        arrow_1.style.opacity = '1';
        arrow_r.style.opacity = '1';
        // 清除计数器
        clearInterval(timer);
        timer = null;
    })
    banner_focus.addEventListener('mouseleave', function () {
        arrow_1.style.opacity = '0';
        arrow_r.style.opacity = '0';
        timer = setInterval(function () {
            arrow_r.click();
        }, 2000)
    })
    for (var i = 0; i < yuan_ul.children.length; i++) {
        yuan_ul.children[i].addEventListener('click', function () {
            for (var i = 0; i < yuan_ul.children.length; i++) {
                yuan_ul.children[i].style.backgroundColor = '#fff';
            }
            this.style.backgroundColor = 'seagreen';
            num = this.getAttribute('index');
            circle = this.getAttribute('index');
            animate(banner_ul, -this.getAttribute('index') * 1518);
        })
    }
    // 右侧按钮
    var flag = true;
    arrow_r.addEventListener('click', function () {
        if (flag) {
            flag=false;
            if (num == 3) {
                banner_ul.style.left = 0;
                num = 0;
            }

            num++;
            circle++;
            if (circle == 3)
                circle = 0;
            animate(banner_ul, -num * 1518,function(){
                flag=true;
            });
            for (var i = 0; i < yuan_ul.children.length; i++) {
                yuan_ul.children[i].style.backgroundColor = '#fff';
            }
            yuan_ul.children[circle].style.backgroundColor = 'seagreen';
        }

    })
    // 左侧按钮
    arrow_1.addEventListener('click', function () {
        if (flag) {
        flag=false;
        clearInterval(timer);
        if (num == 0) {
            banner_ul.style.left = -3 * 1518 + 'px';
            num = 3;
        }
        num--;
        circle--;
        if (circle < 0)
            circle = 2;
        animate(banner_ul, -num * 1518,function(){
            flag=true;
        });
        for (var i = 0; i < yuan_ul.children.length; i++) {
            yuan_ul.children[i].style.backgroundColor = '#fff';
        }
        yuan_ul.children[circle].style.backgroundColor = 'seagreen';

    }})
    var timer = setInterval(function () {
        arrow_r.click();
    }, 5000)
    // 顶部滚动监听
    var hearder_all = document.querySelector('header');
    var logo1 = hearder_all.querySelector('h1');
    var nav_hearder = document.querySelector('.nav_hearder');
    console.log(logo1);
    document.addEventListener('scroll', function () {
        if (window.pageYOffset >= hearder.offsetHeight) {
            hearder_all.style.backgroundColor = '#fff';
            hearder_all.className = 'yy';
            logo1.className = 'logo1';
            // console.log(nav_hearder);
            for (var i = 0; i < nav_hearder.children.length; i++) {
                nav_hearder.children[i].children[0].style.color = '#000';
            }
        }
        else {
            hearder_all.style.backgroundColor = 'transparent';
            hearder_all.className = '';
            logo1.className = '';
            for (var i = 0; i < nav_hearder.children.length; i++) {
                nav_hearder.children[i].children[0].style.color = '#fff';
            }
        }

    })

    // 业务滚动监听
    var company = document.querySelector('.company');
    var focus = document.querySelector('.focus');
    var yw = document.querySelector('.yw');
    var service_img = document.querySelector('.service_img');
    var cp = document.querySelector('.product_h1');
    var product_img = document.querySelector('.product_img');
    var service = document.querySelector('.service');
    console.log(yw);
    document.addEventListener('scroll', function () {
        if (window.pageYOffset >= (company.offsetHeight + focus.offsetHeight - 400)) {
            yw.style.top = '0px';
            yw.style.opacity = '1';
            service_img.style.top = '30px';
            service_img.style.opacity = '1';
        }
        else {
            yw.style.top = '-200px';
            service_img.style.top = '100px';
            yw.style.opacity = '0';
            service_img.style.opacity = '0';
        }
        if (window.pageYOffset >= (service.offsetHeight + company.offsetHeight + focus.offsetHeight + -400)) {
            cp.style.top = '50px';
            product_img.style.top = '90px';
            cp.style.opacity = '1';
            product_img.style.opacity = '1';
        }
        else {
            cp.style.top = '-200px';
            product_img.style.top = '24px';
            cp.style.opacity = '0';
            product_img.style.opacity = '0';
        }
    })

    // 新闻拖拽
    var news_item = document.querySelector('.news_item');
    console.log(news_item);
    news_item.addEventListener('mousedown', function (e) {
        var x = e.pageX - news_item.offsetLeft;
        function move(e) {
            news_item.style.left = e.pageX - x + 'px';
        }
        document.addEventListener('mousemove', move)
        document.addEventListener('mouseup', function (e) {
            document.removeEventListener('mousemove', move);
        })
    })
    document.ondragstart = function () {
        undefined
        return false;
    };
    // 返回顶部
    var gotop = document.querySelector('.gotop');
    console.log(gotop);
    gotop.onclick = function () {
        animate1(window, 0);
    }
})
